
const db=require("../db/index")

//一级评论
exports.sendFirstComment=(req,res)=>{
    const blogid=req.params.blogid
    const userid=req.auth.id
    const username=req.auth.username
    const commentcontent=req.fields.commentcontent
    if (!blogid) return res.R("动态id为空！")
    if(!commentcontent)return res.R("消息不允许为空！")

    const sql="insert into comment (uid,bid,commentcontent,username) values (?,?,?,?)"
    db.query(sql,[userid,blogid,commentcontent,username],(err,results)=>{
        if(err)return res.R(err)
        if(results.affectedRows!==1)return res("评论失败！")
        res.send({
            message:"评论成功！",
            status:200

        })
    })
}

//二级评论
exports.sendSecondComment=(req,res)=>{
    const firstuid=Number(req.body.firstuid)
    const cid=req.params.cid
    const commentcontent=req.body.commentcontent
    const seconduid=req.auth.id
    const secondusername=req.auth.username
    const firstusername=req.body.firstusername
    const sql="insert into secondcomment (firstuid,cid,commentcontent,seconduid,secondusername,firstusername) values (?,?,?,?,?,?)"
    db.query(sql,[firstuid,cid,commentcontent,seconduid,secondusername,firstusername],(err,results)=>{
        if(err)return res.R(err)
        if (results.affectedRows!==1)return res.R("评论失败！")
        res.send({
            message:"评论成功！",
            status:200
        })
    })
}
